import Vue from 'vue'
import App from './App.vue'
import router from './router'
//导入 vuex
import store from './store/index'

Vue.config.productionTip = false  //禁止生产环境

//引入全局的CSS
import  './assets/css/global.css'

import axios from 'axios'

axios.interceptors.request.use((config)=>{
  let  token = sessionStorage.getItem("token");
  if (token) {
    config.headers['token'] = token ;
  }
  return config ;
})

axios.interceptors.response.use((config) =>{
  let data = config.data ;
  console.log(config.data)

  //把data字符串转成 json对象
  //let parse = JSON.parse(data);
  if (data.code == 403) {
    vueApp.$message({
      type:'error',
      message:data.msg,
      duration:1000
    });
    vueApp.$router.push("/");
  }
  return config ;
})

//设置默认地址
axios.defaults.baseURL = "http://localhost:8088"
//绑定到Vue的原型对象上
Vue.prototype.$axios = axios

//引入elementui
import ELementUI from 'element-ui'

Vue.use(ELementUI)
import 'element-ui/lib/theme-chalk/index.css';

//引入 qs
import qs from 'qs'
Vue.prototype.$qs = qs

/*
  qs ：queryString   作用
  {'name':'admin','pass':'123'}
  name=admin&pass=123
 */

let vueApp = new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
